Skip to content

fix: Keep a failing background watcher from breaking a successful actor call - #1027

Draft
vdusek wants to merge 9 commits into
masterfrom
fix/background-watchers-break-successful-call
Draft

fix: Keep a failing background watcher from breaking a successful actor call#1027
vdusek wants to merge 9 commits into
masterfrom
fix/background-watchers-break-successful-call

Conversation

@vdusek

@vdusek vdusek commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Fix

actor.call() with the default logger='default' could raise on a run that had already succeeded. A status poll that failed after retries left the exception on the watcher task; stop() then cancelled an already-finished task and awaited it, re-raising past except asyncio.CancelledError. The sync twin leaked the same failure out of its thread.

Fixes, all on that path:

  • Both watcher loops now use the handler StreamedLog._stream_log already had — warn on is_timeout_error, logger.exception otherwise — so a failed poll is reported instead of surfacing as a failure of the run.
  • The sync watcher's thread is a daemon, so a watcher whose loop never terminates (missing run) cannot hold up interpreter shutdown.
  • StreamedLog.stop() closes the stream response and bounds its join with _stop_timeout_s (5s), instead of joining unbounded on a stream that may not speak for hours.

Closing the response alone is not enough: on impit 0.13.2 Response.close() returns immediately and sets is_closed=True, but a reader blocked in iter_bytes() stays blocked, and closing the Client does not release it either. The close is kept because it is correct for a custom HTTP client; the bounded join is what makes stop() return.

5 new unit tests plus an integration test that fails a real run's background status polls, each red before the fix.

Why stop() is bounded this way

The bound is the third pass over the same problem, so for context:

Trade-off: a thread that outlives the 5s cap keeps running as a daemon, so stop() can return before the tail is flushed. It does not happen on the actor.call() path, where the run's EOF ends the thread first — measured at 0.000s over repeated apify/hello-world runs.

✍️ Drafted by Claude Code

@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Aug 21, 2026
@vdusek vdusek self-assigned this Aug 21, 2026
@github-actions github-actions Bot added this to the 147th sprint - Tooling team milestone Aug 21, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Aug 21, 2026
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.34884% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.96%. Comparing base (df80da1) to head (46d7202).

Files with missing lines Patch % Lines
src/apify_client/_status_message_watcher.py 90.90% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1027   +/-   ##
=======================================
  Coverage   94.95%   94.96%           
=======================================
  Files          58       58           
  Lines        5436     5463   +27     
=======================================
+ Hits         5162     5188   +26     
- Misses        274      275    +1     
Flag Coverage Δ
integration 91.63% <69.76%> (-0.09%) ⬇️
unit 85.86% <95.34%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants